<?php
	
class Liste extends Element{
	
	const 
		DL = 0, OL = 1, UL = 2, 
		DECIMAL = 3, LOWER_ROMAN = 4, UPPER_ROMAN = 5, 
		LOWER_ALPHA = 6, UPPER_ALPHA = 7, LOWER_LATIN = 8, UPPER_LATIN = 9, 
		DISC = 10, CIRCLE = 11, SQUARE = 12, NONE = 13;

	private $authorizedElements = array("ElementList");
	
	private $type;
	
	public function __construct($type){
		parent::__construct($this->authorizedElements);
		$this->type = $type;
	}
	
	public function __toString(){
		$elements = $this->get_elements();
		switch($this->type){
			case self::DL : 			{$text = '<dl>'; break;}
			case self::OL : 			{$text = '<ol>'; break;}
			case self::DECIMAL : 		{$text = '<ol style="list-style-type:decimal;">'; break;}
			case self::LOWER_ROMAN : 	{$text = '<ol style="list-style-type:lower-roman;">'; break;}
			case self::UPPER_ROMAN : 	{$text = '<ol style="list-style-type:upper-roman;">'; break;}
			case self::LOWER_ALPHA : 	{$text = '<ol style="list-style-type:lower-alpha;">'; break;}
			case self::UPPER_ALPHA : 	{$text = '<ol style="list-style-type:upper-alpha;">'; break;}
			case self::LOWER_LATIN : 	{$text = '<ol style="list-style-type:lower-latin;">'; break;}
			case self::UPPER_LATIN : 	{$text = '<ol style="list-style-type:upper-latin;">'; break;}
			case self::DISC : 			{$text = '<ul style="list-style-type:disc;">'; break;}
			case self::CIRCLE : 		{$text = '<ul style="list-style-type:circle;">'; break;}
			case self::SQUARE : 		{$text = '<ul style="list-style-type:square;">'; break;}
			case self::NONE : 			{$text = '<ul style="list-style-type:none;">'; break;}
			default : 					{$text = '<ul>';}
		}
		switch($this->type){
			case self::DL : {
				foreach($elements as $element){
					$text .= '<dd>'.(string)$element.'</dd>';
				}
				break;
			}
			default : {
				foreach($elements as $element){
					$text .= '<li>'.(string)$element.'</li>';
				}
			}
		}
		switch($this->type){
			case self::DL : 			{$text .= '</dl>'; break;}
			case self::OL :
			case self::DECIMAL :
			case self::LOWER_ROMAN :
			case self::UPPER_ROMAN :
			case self::LOWER_ALPHA :
			case self::UPPER_ALPHA :
			case self::LOWER_LATIN :
			case self::UPPER_LATIN : 	{$text .= '</ol>'; break;}
			case self::DISC :
			case self::CIRCLE :
			case self::SQUARE :
			case self::NONE :
			default : 					{$text .= '</ul>';}
		}
		return $text;
    }
}

function entier_romain($entier)
{
    $entier = intval($entier);
    if($entier<1 || $entier>9999)return "";
    
    $rom[3][4];
    $rom[3] = array("M", "", "", "");
    $rom[2] = array("C", "CD", "D", "CM");
    $rom[1] = array("X", "XL", "L", "XC");
    $rom[0] = array("I", "IV", "V", "IX");

    $i = 1;
    $n = 0;
    $romain = "";
    
    for($n=0; $n<4; $n++)
    {
    $chiffre = intval(($entier % ($i*10))/$i);
    if($n<3)
    {
        if($chiffre<4)
        {
        while($chiffre>0)
        {
            $romain = $rom[$n][0].$romain;
            $chiffre--;
        }
        }
        elseif($chiffre==4)
        $romain = $rom[$n][1].$romain;
        elseif($chiffre<9)
        {
        while($chiffre>5)
        {
            $romain = $rom[$n][0].$romain;
            $chiffre--;
        }
        $romain = $rom[$n][2].$romain;
        }
        else
        $romain = $rom[$n][3].$romain;
    }
    else
    {
        while($chiffre>0)
        {
        $romain = $rom[$n][0].$romain;
        $chiffre--;
        }
    }
    $i = $i*10;
    }
    return $romain;
}
?>